package student.action;

import com.opensymphony.xwork2.ActionSupport;

import edu.student.models.Enrollment;
import edu.student.models.Semester;
import edu.student.models.Subject;

public class ModifyGrades extends ActionSupport{
	private String rollNo;
	private String semesterName;
	private String subjectName;
	private String grade;
	private String gradePt;
	private String result;
	private String msg = "";
	private String commandButton = "";
	public String getCommandButton() {
		return commandButton;
	}
	public void setCommandButton(String commandButton) {
		this.commandButton = commandButton;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public String getRollNo() {
		return rollNo;
	}
	public void setRollNo(String rollNo) {
		this.rollNo = rollNo;
	}
	public String getSemesterName() {
		return semesterName;
	}
	public void setSemesterName(String semesterName) {
		this.semesterName = semesterName;
	}
	public String getSubjectName() {
		return subjectName;
	}
	public void setSubjectName(String subjectName) {
		this.subjectName = subjectName;
	}
	public String getGrade() {
		return grade;
	}
	public void setGrade(String grade) {
		this.grade = grade;
	}
	
	public String getGradePt() {
		return gradePt;
	}
	public void setGradePt(String gradePt) {
		this.gradePt = gradePt;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public String execute() throws Exception {
		/*update values in database*/
		System.out.println("5555555555555555 Just entered Execute of ModifyGrade.java");
		if(this.commandButton.startsWith("Save")){
			System.out.println("2222222222 in modify grades execute");
			int semesterId = Semester.getSemesterId(semesterName);
			int subjectId = Subject.getSubjectId(subjectName);
			int rs=Enrollment.updateResultInEnroll(rollNo, semesterId, subjectId, grade, result,gradePt);
			if(rs==0){
				msg="Error in updating";
				System.out.println(msg);
				return "error";
			}
			msg="Student Result updated.";
			return "success";
		}
		if(this.commandButton.startsWith("Back")){
		return "success";
		}
	
		if(this.msg==""){
			System.out.println("OMG HELP ME !!!!\n");
			msg="abc";
		return "initial";}
		
			return "success";
	}
}
